<?php
/**
 * Created by JetBrains PhpStorm.
 * User: ivan
 * Date: 9/14/12
 * Time: 1:35 PM
 * To change this template use File | Settings | File Templates.
 */


class Db_Products_CoverTypes extends Common {
    protected static $tableName = TAB_COVER_TYPES;
    protected static $dbFields = array(
        'id',
        'ct_name',
        'ct_hard_cover',
        'deleted'
    );

    /**
     * @var Db_Products_CoverTypes
     */
    public $objectArray;

    public $id;
    public $ct_name;
    public $ct_hard_cover;
    public $deleted;

    function __construct($value=NULL, $fieldName=NULL) {
        parent::__construct($value, $fieldName);
    }

	public static function getAllCoverTypes() {
		$sql = 'SELECT `ct`.*, IF(`ct`.`id` = `p`.`p_cover_type_id`, 1, 0) AS `is_used`
				FROM ?f AS `ct`
				LEFT JOIN ?f AS `p` ON `ct`.`id` = `p`.`p_cover_type_id` AND `p`.`deleted` = 0
				WHERE `ct`.`deleted` = 0
				GROUP BY `ct`.`id` ;';
		return self::$DB->select($sql, self::$tableName, TAB_PRODUCTS);
	}
}